home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / CALib & You… / Source / CALib / Implementation / ProxyPart / CAProxyDebug.cpp next >
Encoding:
C/C++ Source or Header  |  1995-12-07  |  1.3 KB  |  99 lines  |  [TEXT/MPS ]

  1.  
  2. #ifndef _CAPROXYDEBUG_
  3. #include "CAProxyDebug.h"
  4. #endif
  5.  
  6.  
  7. #ifndef _PASCALSTR_
  8. #include <PasclStr.h>
  9. #endif
  10.  
  11. #include <string.h>
  12. #include <stdio.h>
  13. #include <stdarg.h>
  14.  
  15. static     FSSpec            gLogSpec;
  16. static    short            gLogRefNum;
  17.  
  18.  
  19. static void WriteToTraceFile (char* message);
  20.  
  21.  
  22. void InitTracing(FSSpec* spec, Boolean flushLog)
  23. {
  24.     FInfo    ignore;
  25.  
  26.     if (spec == NULL)
  27.     {
  28.         FSMakeFSSpec (0, 2, "\pCAProxyPart Trace Log" , &gLogSpec);
  29.     }
  30.     else
  31.     {
  32.         gLogSpec = *spec;
  33.     }
  34.     
  35.     if (FSpGetFInfo (&gLogSpec, &ignore))
  36.     {
  37.         FSpCreate (&gLogSpec, 'ttxt', 'TEXT', 0);
  38.     }
  39.     
  40.     FSpOpenDF (&gLogSpec, fsRdWrPerm, &gLogRefNum);
  41.     
  42.     if (flushLog)
  43.         SetEOF (gLogRefNum, 0);
  44.  
  45. }
  46.  
  47.  
  48. static void WriteToTraceFile (char* message)
  49. {
  50. long    count;
  51. char    eol[2];
  52. long    eof;
  53.  
  54.  
  55.     FSpOpenDF (&gLogSpec, fsRdWrPerm, &gLogRefNum);
  56.     GetEOF (gLogRefNum, &eof);
  57.     SetFPos (gLogRefNum, fsFromStart, eof);
  58.     
  59.     count = strlen (message);
  60.  
  61.     FSWrite (gLogRefNum, &count, message);
  62.     
  63.     count = 1;
  64.     eol[0] = 0x0D;
  65.     FSWrite (gLogRefNum, &count, eol);
  66.     
  67.     FSClose(gLogRefNum);
  68.     
  69.     
  70. }
  71.  
  72. void _Trace(short traceLevel, char *fmt, ... )
  73. {
  74.     if (traceLevel >= TRACELEVEL)
  75.     {
  76.     
  77.         char msg[512];
  78.         strcpy(msg, "Log: ");
  79.         va_list args;
  80.         va_start(args,fmt);
  81.         vsprintf(msg+strlen(msg),fmt,args);
  82.         va_end(args);
  83.         strcat (msg, "");
  84.         
  85.         WriteToTraceFile (msg);
  86.         
  87.     
  88.     }
  89. }
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.